package com.biboheart.adapter.express.support;

import com.biboheart.adapter.express.actuator.GenericActuator;
import com.biboheart.adapter.support.utils.ObjectTypeUtils;

final class MaxActuator implements GenericActuator {
    @Override
    public Object execute(Object source, Object... args) {
        if (null == source) {
            return null;
        }
        if (args.length == 0) {
            return source;
        }
        Object arg = args[0];
        if (!(source instanceof Number) || !(arg instanceof Number)) {
            return null;
        }
        if ((source instanceof Double) || (arg instanceof Double)) {
            return Math.max(ObjectTypeUtils.convertType(source, Double.class), ObjectTypeUtils.convertType(arg, Double.class));
        }
        if ((source instanceof Float) || (arg instanceof Float)) {
            return Math.max(ObjectTypeUtils.convertType(source, Float.class), ObjectTypeUtils.convertType(arg, Float.class));
        }
        if ((source instanceof Long) || (arg instanceof Long)) {
            return Math.max(ObjectTypeUtils.convertType(source, Long.class), ObjectTypeUtils.convertType(arg, Long.class));
        }
        return Math.max(ObjectTypeUtils.convertType(source, Integer.class), ObjectTypeUtils.convertType(arg, Integer.class));
    }
}
